home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 3_7.lha / 3_7 / 3_7c.c < prev    next >
Text File  |  1993-08-08  |  538b  |  24 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. /  Count the characters within the string.
  6. /  Version 3
  7.  
  8. /  Look in the first maxlen characters for a null
  9. /  character.  Return its position (the length of
  10. /  the string), or maxlen if it is not found.
  11.  
  12. nt strnlen(const char *s, int maxlen)
  13.  
  14.    if (!s)
  15. return 0;
  16.    int savemaxlen = maxlen;
  17.  
  18.    while (maxlen-- > 0)
  19. if (*s++ == '\0')
  20.     return savemaxlen - maxlen - 1;
  21.  
  22.    return savemaxlen;
  23.  
  24.